package br.com.gsc.model.tableMapping;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(name = "tb_products")
@Transactional
public class Product {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	long id;
	
	private String name;
	
	@ManyToOne
	@JoinColumn(name="companies_id")
	private Company company;
	
	@OneToMany(mappedBy="product",cascade=CascadeType.ALL)
	@OrderBy("createdIn desc")
	private List<Topic> listOfTopics;
	
	@ManyToMany(mappedBy = "listOfProducts")	
	List<Operator> listOfowners = new ArrayList<Operator>();
	
	private String productImage = "thumb_default_company.png";
	
	public String getProductImage() {
		return productImage;
	}

	public void setProductImage(String productImage) {
		this.productImage = productImage;
	}

	public Product(String name){
		this.name = name;
	}
	
	public Product(){
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public List<Topic> getListOfTopics() {
		return listOfTopics;
	}

	public void setListOfTopics(List<Topic> listOfTopics) {
		this.listOfTopics = listOfTopics;
	}

	public List<Operator> getListOfowners() {
		return listOfowners;
	}

	public void setListOfowners(List<Operator> listOfowners) {
		this.listOfowners = listOfowners;
	}
	
	public String toString(){
		return this.getName();
	}
	
}
